package org.mzyyn.qr;


import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * @author lixiaopeng
 * @date 2022-07-17 10:10
 */
public class MybatisPlusGenerator {
    public static void main(String[] args) throws Exception {

        FastAutoGenerator fastAutoGenerator = FastAutoGenerator.create(
                "jdbc:mysql://43.138.27.38:3306/jifenduihuan?autoReconnect=true&autoReconnectForPools=true&useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull",
                "qianren",
                "wCM%Ufl7lT$p!g5&"
        );

        //
        String output = System.getProperty("user.dir");

        fastAutoGenerator.globalConfig(builder -> {
            builder.author("lipeng") // 设置作者
                    .disableOpenDir() // 关闭文件夹打开功能
                    .outputDir(output + "/src/main/java/"); // 指定输出目录
        });
        fastAutoGenerator.packageConfig(builder -> {
            builder.parent("org.mzyyn.qr") // 设置父包名
                    .mapper("mapper") // 设置 mapper 包名
             ;
        });

        fastAutoGenerator.packageConfig(builder -> {
            builder.xml("mapperxml").pathInfo(Collections.singletonMap(OutputFile.xml, output + "/src/main/resources/mapper"));
        });

        fastAutoGenerator.strategyConfig(builder -> {
            builder.addInclude(
                    "t_duitaofang"
            ) // 设置需要生成的表名
                    .addTablePrefix("t_") // 设置过滤表前缀
                    .entityBuilder().enableLombok().enableFileOverride()
                    .convertFileName(entityName -> entityName + "PO"); //开启lombok的支持
//                    .mapperBuilder() // 设置 mapper 生成策略
//                    .enableBaseResultMap();
        });
        fastAutoGenerator.injectionConfig(builder -> {
//            builder.fileOverride(); // 覆盖生成的文件
        });

        fastAutoGenerator.templateConfig(builder -> {

//            builder.disable(TemplateType.CONTROLLER, TemplateType.SERVICE, TemplateType.SERVICE_IMPL); // 禁止生成对应模板
        });
        fastAutoGenerator.templateEngine(new FreemarkerTemplateEngine());
        fastAutoGenerator.execute();// 使用Freemarker引擎模板，默认的是Velocity引擎模板

    }

}
